package nc.bs.pub.action;

import java.util.Arrays;

import nc.bs.framework.common.NCLocator;
import nc.bs.pub.compiler.IWorkFlowRet;
import nc.impl.pubapp.pattern.rule.processer.CompareAroundProcesser;
import nc.vo.pub.BusinessException;
import nc.vo.pub.compiler.PfParameterVO;
import nc.vo.pub.VOStatus;
import nc.vo.uap.pf.PFBusinessException;
import nc.vo.pubapp.pattern.model.entity.bill.AbstractBill;
import nc.vo.pubapp.pattern.model.meta.entity.bill.IBillMeta;
import nc.vo.pub.CircularlyAccessibleValueObject;
import nccloud.commons.lang.StringUtils;
import nc.codeplatform.framework.service.AbstractPfScriptAction;
import nc.vo.sjxm.sjxm.AggSjxmVO;
import nc.itf.hrpbm.sjxm.sjxmh.ISjxmHVOService;

public class N_SJXM_APPROVE extends AbstractPfScriptAction<AggSjxmVO>{
	
	public N_SJXM_APPROVE(){
		super();
	}
	
	@Override
	protected Object process(PfParameterVO paraVO) throws BusinessException {
		try {
			ISjxmHVOService service = NCLocator.getInstance().lookup(ISjxmHVOService.class);
			AggSjxmVO[] vos = (AggSjxmVO[])this.getVos();
			Arrays.stream(vos).forEach(v-> v.getParent().setStatus(VOStatus.UPDATED));
			
			IWorkFlowRet  workFlowRet = (IWorkFlowRet)this.procActionFlow(paraVO);
			
			vos = service.callbackAPPROVE(vos);
			
			return workFlowRet==null?vos:workFlowRet;
		}catch(Exception ex) {
			if (ex instanceof BusinessException) {
		        throw (BusinessException) ex;
		      }
	        throw new PFBusinessException(ex.getMessage(), ex);
		}
	}
	
	protected void before(PfParameterVO paraVO)  throws BusinessException{
		AggSjxmVO vo = (AggSjxmVO)this.getVo();
		if(StringUtils.isEmpty(vo.getPrimaryKey())){
			throw new BusinessException("当前单据未执行保存动作脚本，如果配置了业务流程定义，请检查动作驱动配置！");
		}
	}
	/**
	 * 在这里添加动作脚本的环绕监听
	 *  父类AbstractPfScriptAction的runComClass方法中会执行前监听事件和后监听事件
	 *  每一个监听类都需要实现nc.impl.pubapp.pattern.rule.IRule<E>接口
	 */
	@Override
	protected CompareAroundProcesser<AggSjxmVO> getAroundProcessor(PfParameterVO paraVO)  throws BusinessException{
		return null;
	}
}
